
#
# Sets:
# DirectInput_ROOT_DIR
# DirectInput_INCLUDE_DIRS
# DirectInput_LIBRARY_DIRS
# DirectInput_LIBRARIES
# DirectInput_FOUND
#

macro( DirectInput_STATUS_MESSAGE _msg )
  if( NOT DirectInput_FIND_QUIET)
    message( STATUS ${_msg} )
 endif()
endmacro()

#
# Set DirectInput_FOUND to true here, 
# Is set to false later if something was not found
#
SET(DirectInput_FOUND TRUE)

#
# SET DirectInput_ROOT_DIR
#
SET( DirectInput_ROOT_SEARCH_PATH 
  $ENV{DIRECTINPUT_ROOT_DIR}
  $ENV{DXSDK_DIR}
)
find_path( DirectInput_ROOT_DIR NAMES include/dinput.h 
  PATHS ${DirectInput_ROOT_SEARCH_PATH}
)

#
# SET DirectInput_INCLUDE_DIRS
#
#SET( DirectInput_INCLUDE_DIRS "DirectInput_INCLUDE_DIRS-NOTFOUND")
find_path( DirectInput_INCLUDE_DIRS NAMES dinput.h
  PATHS
    $ENV{DIRECTINPUT_INCLUDE_DIRS}
    ${DirectInput_ROOT_DIR}/include
)
if( "${DirectInput_INCLUDE_DIRS}" STREQUAL "DirectInput_INCLUDE_DIRS-NOTFOUND" )
    DirectInput_STATUS_MESSAGE( "DirectInput - dinput.h : * NOT FOUND *")
    SET(DirectInput_FOUND FALSE)
else()
  DirectInput_STATUS_MESSAGE( "DirectInput - dinput.h : ${DirectInput_INCLUDE_DIRS}")
endif()


#
# SET DirectInput_LIBRARIES
#
SET( DirectInput_LIBRARIES dinput8.lib dxguid.lib )


#
# SET DirectInput_LIBRARY_DIRS
#
#SET( DirectInput_LIBRARY_DIRS "" )
FOREACH( LIBRARY_FILE ${DirectInput_LIBRARIES} )
  SET( LIBRARY_PATH "LIBRARY_PATH-NOTFOUND" )
  find_path( LIBRARY_PATH NAMES ${LIBRARY_FILE} 
    PATHS 
      $ENV{DIRECTINPUT_LIBRARY_DIRS}
      ${DirectInput_ROOT_DIR}/Lib
      ${DirectInput_ROOT_DIR}/Lib/x86
  )
  IF( "${LIBRARY_PATH}" STREQUAL "LIBRARY_PATH-NOTFOUND" )
    DirectInput_STATUS_MESSAGE( "DirectInput - ${LIBRARY_FILE} : * NOT FOUND *")
    SET(DirectInput_FOUND FALSE)
  ELSE()
    DirectInput_STATUS_MESSAGE( "DirectInput - ${LIBRARY_FILE} : ${LIBRARY_PATH}")
    LIST( FIND DirectInput_LIBRARY_DIRS ${LIBRARY_PATH} _result )
    if( ${_result} LESS 0 )
      SET( DirectInput_LIBRARY_DIRS ${DirectInput_LIBRARY_DIRS} ${LIBRARY_PATH} )
    endif()
  ENDIF()
ENDFOREACH()


#
# PRINT STATUS
#

#message(STATUS "DirectInput_ROOT_DIR : ${DirectInput_ROOT_DIR}")
#message(STATUS "DirectInput_INCLUDE_DIRS : ${DirectInput_INCLUDE_DIRS}")
#message(STATUS "DirectInput_LIBRARY_DIRS : ${DirectInput_LIBRARY_DIRS}")
#message(STATUS "DirectInput_LIBRARIES : ${DirectInput_LIBRARIES}")
#message(STATUS "DirectInput_FOUND : ${DirectInput_FOUND}")

if( NOT DirectInput_FOUND ) 
  if( ${DirectInput_FIND_REQUIRED} )
    message( FATAL_ERROR "DirectInput NOT found.")
  else()
    message( STATUS "DirectInput NOT found.")
  endif()
else()
  DirectInput_STATUS_MESSAGE( "DirectInput Found: TRUE.")
endif()







    
    